#!/usr/bin/env python
from math import sin, cos, pi

import pygame

import blocks
from quadtree import QuadTree

class Level:
    def __init__(self, x=0, y=0, w=640, h=480):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        
        self.plans = set()
        self.blocks = set()
        
        self.planTree = QuadTree(boundingRect=(x, y, x+w, y+h))
        self.quadTree = QuadTree(boundingRect=(x, y, x+w, y+h))
    
    def save(self):
        pass
    
    def load(self):
        self.blocks |= set(blocks.Circle(320 - 192 + 384/16*i, 250 + i%2*24, 16.0) for i in range(16))
        self.blocks |= set(blocks.Circle(320 - 192 + 384/16*i, 298 + i%2*24, 16.0) for i in range(16))
        
        r0 = 48
        r1 = 48 + 16
        self.blocks |= set(blocks.Arc(140, 128, r0, r1, pi/7*i, pi/7*(i+0.9)) for i in range(7))
        self.blocks |= set(blocks.Arc(320, 80,  r0, r1, pi/7*i, pi/7*(i+0.9)) for i in range(7))
        self.blocks |= set(blocks.Arc(500, 128, r0, r1, pi/7*i, pi/7*(i+0.9)) for i in range(7))
        
        self.blocks |= set(blocks.Capsule(32+48.0*i, 360.0, 48+48.0*i, 360.0, 8.0) for i in range(12))
        self.blocks |= set(blocks.Rectangle(32+48.0*i, 400.0, 24.0, 16.0) for i in range(13))
        
        for block in self.blocks:
            self.quadTree.insert(block)
    
    def update(self):
        pass
    
    def draw(self, display):
        for block in self.blocks:
            block.draw(display)